package com.feather.common.pojo.adapter;

import java.util.Map;

import com.feather.common.pojo.PojoConfiguration;
import com.feather.common.pojo.PojoConfigurationBuilder;
import com.feather.common.pojo.PojoEntry;

/**
 * @author flogyin
 */
public abstract class AbstractPojoConfiguration implements PojoConfiguration {
	protected PojoConfigurationBuilder	builder;
	protected Object					context;
	protected String					name;
	protected Map<String, PojoEntry>	pojoEntryMap;

	public AbstractPojoConfiguration(PojoConfigurationBuilder builder, String name, Object context, Map<String, PojoEntry> map) {
		this.builder = builder;
		this.name = name;
		this.context = context;
		this.pojoEntryMap = map;
	}

	@Override
	public Map<String, PojoEntry> get() {
		return this.pojoEntryMap;
	}

	@Override
	public String getName() {
		return this.name;
	}

	@Override
	public void setName(String name) {
		this.name = name;
	}

	@Override
	public Object getContext() {
		return this.context;
	}

	@Override
	public PojoEntry get(String id) {
		return (PojoEntry) this.pojoEntryMap.get(id);
	}

	@Override
	public Object getObject(String id) {
		PojoEntry entry = get(id);
		return entry != null ? entry.getObject() : null;
	}

	@Override
	public void add(PojoEntry pojoEntry) {
		String id = pojoEntry.getInfo().getId();
		this.pojoEntryMap.put(id, pojoEntry);
	}

	@Override
	public PojoEntry remove(String id) {
		return (PojoEntry) this.pojoEntryMap.remove(id);
	}

	@Override
	public PojoConfigurationBuilder getBuilder() {
		return this.builder;
	}
}
